<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>车辆管理</title>
	<meta name="decorator" content="ani"/>
	<script type="text/javascript">
		var validateForm;
		var $table; // 父页面table表格id
		var $topIndex;//弹出窗口的 index
		function doSubmit(table, index){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
		  if(validateForm.form()){
			  $table = table;
			  $topIndex = index;
			  jp.loading();
			  $("#inputForm").submit();
			  return true;
		  }

		  return false;
		}

		$(document).ready(function() {
			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
					jp.post("${ctx}/tms/truckOwner/save",$('#inputForm').serialize(),function(data){
						if(data.success){
	                    	$table.bootstrapTable('refresh');
	                    	jp.success(data.msg);
	                    	jp.close($topIndex);//关闭dialog

	                    }else{
            	  			jp.error(data.msg);
	                    }
					})
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
		});
		
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
			$(list+idx).find(".form_datetime").each(function(){
				 $(this).datetimepicker({
					 format: "YYYY-MM-DD HH:mm:ss"
			    });
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body class="bg-white">
		<form:form id="inputForm" modelAttribute="truckOwner" action="${ctx}/tms/truckOwner/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<table class="table table-bordered">
		   <tbody>
				<tr>
					<td class="width-15 active"><label class="pull-right">车属单位：</label></td>
					<td class="width-35">
						<form:input path="unit" htmlEscape="false"    class="form-control "/>
					</td>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>车主姓名：</label></td>
					<td class="width-35">
						<form:input path="name" htmlEscape="false"    class="form-control required"/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">车主电话：</label></td>
					<td class="width-35">
						<form:input path="phone" htmlEscape="false"    class="form-control  isTel"/>
					</td>
					<td class="width-15 active"><label class="pull-right">车主身份证：</label></td>
					<td class="width-35">
						<form:input path="idCard" htmlEscape="false"    class="form-control  isIdCardNo"/>
					</td>
				</tr>
				<tr>
					<td class="width-15 active"><label class="pull-right">备注信息：</label></td>
					<td class="width-35">
						<form:textarea path="remarks" htmlEscape="false" rows="4"    class="form-control "/>
					</td>
					<td class="width-15 active"></td>
		   			<td class="width-35" ></td>
		  		</tr>
		 	</tbody>
		</table>
		<div class="tabs-container">
            <ul class="nav nav-tabs">
				<li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">车辆表：</a>
                </li>
            </ul>
            <div class="tab-content">
				<div id="tab-1" class="tab-pane fade in  active">
			<a class="btn btn-white btn-sm" onclick="addRow('#trucksList', trucksRowIdx, trucksTpl);trucksRowIdx = trucksRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
			<table class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<th class="hide"></th>
						<th><font color="red">*</font>车牌号</th>
						<th>车型</th>
						<th>车长（M）</th>
						<th>载重(T)</th>
						<th>最大载货体积(m³)</th>
						<th>运输线路一</th>
						<th>运输线路二</th>
						<th>运输线路三</th>
						<th>车辆购买时间</th>
						<th>车辆品牌</th>
						<th>车辆型号</th>
						<th>合作类型</th>
						<th>驾驶员姓名</th>
						<th>驾驶员电话</th>
						<th>驾驶员身份证</th>
						<th>三者险金额(元)</th>
						<th>货物险金额(元)</th>
						<th>承保公司</th>
						<th>保险购买日期</th>
						<th>保险失效日期</th>
						<th>是否顶置</th>
						<th>置顶到期日期</th>
						<th>驾驶员驾驶证照片</th>
						<th>车辆行驶证照片</th>
						<th>车辆保险卡照片</th>
						<th>车辆正面牌照照片</th>
						<th>车辆侧面照片</th>
						<th>浏览数</th>
						<th>分享次数</th>
						<th>修改</th>
						<th>备注信息</th>
						<th width="10">&nbsp;</th>
					</tr>
				</thead>
				<tbody id="trucksList">
				</tbody>
			</table>
			<script type="text/template" id="trucksTpl">//<!--
				<tr id="trucksList{{idx}}">
					<td class="hide">
						<input id="trucksList{{idx}}_id" name="trucksList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="trucksList{{idx}}_delFlag" name="trucksList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>
					
					<td>
						<input id="trucksList{{idx}}_number" name="trucksList[{{idx}}].number" type="text" value="{{row.number}}"    class="form-control required"/>
					</td>
					
					
					<td>
						<select id="trucksList{{idx}}_type" name="trucksList[{{idx}}].type" data-value="{{row.type}}" class="form-control m-b  ">
							<option value=""></option>
							<c:forEach items="${fns:getDictList('truck_type')}" var="dict">
								<option value="${dict.value}">${dict.label}</option>
							</c:forEach>
						</select>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_length" name="trucksList[{{idx}}].length" type="text" value="{{row.length}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_weight" name="trucksList[{{idx}}].weight" type="text" value="{{row.weight}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_maxVolume" name="trucksList[{{idx}}].maxVolume" type="text" value="{{row.maxVolume}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_transportationLineOne" name="trucksList[{{idx}}].transportationLineOne" type="text" value="{{row.transportationLineOne}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_transportationLineTwo" name="trucksList[{{idx}}].transportationLineTwo" type="text" value="{{row.transportationLineTwo}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_transportationLineThree" name="trucksList[{{idx}}].transportationLineThree" type="text" value="{{row.transportationLineThree}}"    class="form-control "/>
					</td>
					
					
					<td>
						<div class='input-group form_datetime' id="trucksList{{idx}}_purchaseTime">
		                    <input type='text'  name="trucksList[{{idx}}].purchaseTime" class="form-control "  value="{{row.purchaseTime}}"/>
		                    <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
		                    </span>
		                </div>						            
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_vehicleBrand" name="trucksList[{{idx}}].vehicleBrand" type="text" value="{{row.vehicleBrand}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_vehicleModel" name="trucksList[{{idx}}].vehicleModel" type="text" value="{{row.vehicleModel}}"    class="form-control "/>
					</td>
					
					
					<td>
						<select id="trucksList{{idx}}_cooperationType" name="trucksList[{{idx}}].cooperationType" data-value="{{row.cooperationType}}" class="form-control m-b  ">
							<option value=""></option>
							<c:forEach items="${fns:getDictList('cooperation_type')}" var="dict">
								<option value="${dict.value}">${dict.label}</option>
							</c:forEach>
						</select>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_driver" name="trucksList[{{idx}}].driver" type="text" value="{{row.driver}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_phone" name="trucksList[{{idx}}].phone" type="text" value="{{row.phone}}"    class="form-control  isTel"/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_idCard" name="trucksList[{{idx}}].idCard" type="text" value="{{row.idCard}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_threePartyInsurance" name="trucksList[{{idx}}].threePartyInsurance" type="text" value="{{row.threePartyInsurance}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_cargoInsurance" name="trucksList[{{idx}}].cargoInsurance" type="text" value="{{row.cargoInsurance}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_insuranceCompany" name="trucksList[{{idx}}].insuranceCompany" type="text" value="{{row.insuranceCompany}}"    class="form-control "/>
					</td>
					
					
					<td>
						<div class='input-group form_datetime' id="trucksList{{idx}}_purchaseDate">
		                    <input type='text'  name="trucksList[{{idx}}].purchaseDate" class="form-control "  value="{{row.purchaseDate}}"/>
		                    <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
		                    </span>
		                </div>						            
					</td>
					
					
					<td>
						<div class='input-group form_datetime' id="trucksList{{idx}}_expirationDate">
		                    <input type='text'  name="trucksList[{{idx}}].expirationDate" class="form-control "  value="{{row.expirationDate}}"/>
		                    <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
		                    </span>
		                </div>						            
					</td>
					
					
					<td>
						<c:forEach items="${fns:getDictList('top')}" var="dict" varStatus="dictStatus">
							<span><input id="trucksList{{idx}}_top${dictStatus.index}" name="trucksList[{{idx}}].top" type="radio" class="i-checks" value="${dict.value}" data-value="{{row.top}}"><label for="trucksList{{idx}}_top${dictStatus.index}">${dict.label}</label></span>
						</c:forEach>
					</td>
					
					
					<td>
						<div class='input-group form_datetime' id="trucksList{{idx}}_topDate">
		                    <input type='text'  name="trucksList[{{idx}}].topDate" class="form-control "  value="{{row.topDate}}"/>
		                    <span class="input-group-addon">
		                        <span class="glyphicon glyphicon-calendar"></span>
		                    </span>
		                </div>						            
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_driverLicensePhoto" name="trucksList[{{idx}}].driverLicensePhoto" type="hidden" value="{{row.driverLicensePhoto}}" maxlength="128" class="form-control"/>
						<sys:ckfinder input="trucksList{{idx}}_driverLicensePhoto" type="files" uploadPath="/tms/truckOwner" selectMultiple="true"/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_vehicleLicensePhotos" name="trucksList[{{idx}}].vehicleLicensePhotos" type="hidden" value="{{row.vehicleLicensePhotos}}" maxlength="128" class="form-control"/>
						<sys:ckfinder input="trucksList{{idx}}_vehicleLicensePhotos" type="files" uploadPath="/tms/truckOwner" selectMultiple="true"/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_insuranceCardPhoto" name="trucksList[{{idx}}].insuranceCardPhoto" type="hidden" value="{{row.insuranceCardPhoto}}" maxlength="128" class="form-control"/>
						<sys:ckfinder input="trucksList{{idx}}_insuranceCardPhoto" type="files" uploadPath="/tms/truckOwner" selectMultiple="true"/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_vehicleFrontPhoto" name="trucksList[{{idx}}].vehicleFrontPhoto" type="hidden" value="{{row.vehicleFrontPhoto}}" maxlength="128" class="form-control"/>
						<sys:ckfinder input="trucksList{{idx}}_vehicleFrontPhoto" type="files" uploadPath="/tms/truckOwner" selectMultiple="true"/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_vehicleSidePhoto" name="trucksList[{{idx}}].vehicleSidePhoto" type="hidden" value="{{row.vehicleSidePhoto}}" maxlength="128" class="form-control"/>
						<sys:ckfinder input="trucksList{{idx}}_vehicleSidePhoto" type="files" uploadPath="/tms/truckOwner" selectMultiple="true"/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_skimAmount" name="trucksList[{{idx}}].skimAmount" type="text" value="{{row.skimAmount}}"    class="form-control "/>
					</td>
					
					
					<td>
						<input id="trucksList{{idx}}_sharingTimes" name="trucksList[{{idx}}].sharingTimes" type="text" value="{{row.sharingTimes}}"    class="form-control "/>
					</td>
					
					
					<td>
						<c:forEach items="${fns:getDictList('is_revise')}" var="dict" varStatus="dictStatus">
							<span><input id="trucksList{{idx}}_revise${dictStatus.index}" name="trucksList[{{idx}}].revise" type="radio" class="i-checks" value="${dict.value}" data-value="{{row.revise}}"><label for="trucksList{{idx}}_revise${dictStatus.index}">${dict.label}</label></span>
						</c:forEach>
					</td>
					
					
					<td>
						<textarea id="trucksList{{idx}}_remarks" name="trucksList[{{idx}}].remarks" rows="4"    class="form-control ">{{row.remarks}}</textarea>
					</td>
					
					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#trucksList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
			</script>
			<script type="text/javascript">
				var trucksRowIdx = 0, trucksTpl = $("#trucksTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
				$(document).ready(function() {
					var data = ${fns:toJson(truckOwner.trucksList)};
					for (var i=0; i<data.length; i++){
						addRow('#trucksList', trucksRowIdx, trucksTpl, data[i]);
						trucksRowIdx = trucksRowIdx + 1;
					}
				});
			</script>
			</div>
		</div>
		</div>
		</form:form>
</body>
</html>